package com.sais.manage.boot.repair.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sais.common.entity.Result;
import com.sais.manage.boot.repair.dto.RepairDTO;
import com.sais.manage.boot.repair.dto.RepairSaveDTO;
import com.sais.manage.boot.repair.dto.RepairSearchDTO;
import com.sais.manage.boot.repair.service.IRepairService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 宿舍管理系统-维修申请 controller 类
 *
 * @author zwp
 * @date 2020/2/2
 **/
@Api(tags = "维修申请管理")
@Slf4j
@CrossOrigin
@RestController
@RequestMapping("/api/repair/repair")
public class RepairController {

    @Resource
    private IRepairService repairService;

    @ApiOperation("维修申请 保存")
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public Result saveRepair(@RequestBody RepairSaveDTO repairSaveDTO) {
        repairService.saveRepair(repairSaveDTO);
        return new Result();
    }

    @ApiOperation("维修申请 删除")
    @RequestMapping(value = "/delete/{repairId}", method = RequestMethod.GET)
    public Result deleteRepair(@PathVariable("repairId") String repairId) {
        repairService.deleteRepair(repairId);
        return new Result();
    }

    @ApiOperation("根据id 查询 维修申请")
    @RequestMapping(value = "/select/{repairId}", method = RequestMethod.GET)
    public Result selectRepair(@PathVariable("repairId") String repairId) {
        RepairDTO repair = repairService.selectRepair(repairId);
        return new Result().data("repair", repair);
    }

    @ApiOperation("分页条件 查询")
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public Result listRepair(RepairSearchDTO searchDTO,
                             @RequestParam(defaultValue = "1") Integer current,
                             @RequestParam(defaultValue = "30") Integer size) {
        Page<RepairDTO> page = repairService.listRepair(current, size, searchDTO);
        return new Result().data("repairs", page);
    }

    @ApiOperation("更改维修状态")
    @RequestMapping(value = "/update/status/{repairId}", method = RequestMethod.GET)
    public Result updateRepairStatus(@PathVariable("repairId") String repairId) {
        repairService.updateRepairStatus(repairId);
        return new Result();
    }


}
